from datetime import datetime, timedelta


def jwt_response_payload_handler(token, user=None, request=None):
    """自定义用户登录成功返回"""

    return {
        'token': token,
        'name': user.name,
        'user_id': user.id
    }


class CalendarUtils:

    def __init__(self):
        self.now = datetime.now()

    def delta_day(self, delta=0):
        """
        :param delta:  偏移量 0 今天, 1 明天 ,2 后天, -1 昨天
        :return:
        """
        return (self.now + timedelta(days=delta)).strftime('%Y-%m-%d')

    def delta_week(self, delta=0):
        """
        :param delta: 偏移量 0 本周, 1 下周, -1 上周
        :return:
        """
        week = self.now.weekday()
        start = (self.now - timedelta(days=week - 7 * delta)).strftime('%H-%m-%d')
        end = (self.now + timedelta(days=6 - week + 7 * delta)).strftime('%H-%m-%d')
        return start, end

    def delta_year(self, delta=0):
        """
        :param delta:   偏移量
        :return:        0今年, -1去年, 1明年 ...
        """

        return self.now.year
